/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jdListaEntidadBuscar.java
 *
 * Created on 22-sep-2010, 10:30:02
 */

package Utiles;

import Utiles.IFrameBusqueda;
import administracion.helper.Utiles_MensajesDialogo;
import java.util.List;
import org.jdesktop.beansbinding.AutoBinding;
import org.jdesktop.beansbinding.BindingGroup;
import org.jdesktop.beansbinding.ELProperty;
import org.jdesktop.swingbinding.JTableBinding;
import org.jdesktop.swingbinding.SwingBindings;
import suministros.ejb30.TO.SimpleEntidadTO;

/**
 *
 * @author Luis_Angel
 */
public class jdListaEntidadBuscar extends javax.swing.JDialog {

    private IFrameBusqueda iframe;
    private List<SimpleEntidadTO> lista;
    /** Creates new form jdListaEntidadBuscar */
    public jdListaEntidadBuscar(java.awt.Frame parent, boolean modal, IFrameBusqueda iframe, String titulo,List<SimpleEntidadTO> lista) {
        super(parent, modal);
        this.iframe = iframe;
        initComponents();
        this.jlblTitulo.setText(titulo);
        this.lista = lista;
        actualizaTablaDetalle(lista);
    }

      private void actualizaTablaDetalle(List<SimpleEntidadTO> lista) {
            BindingGroup bindingGroup = new BindingGroup();


            JTableBinding jTableBinding = SwingBindings.createJTableBinding(AutoBinding.UpdateStrategy.READ, lista, this.jtLista);

            JTableBinding.ColumnBinding columnBinding0 = jTableBinding.addColumnBinding(ELProperty.create("${codigo}"));

            columnBinding0.setColumnName("Codigo");
            columnBinding0.setColumnClass(String.class);
            columnBinding0.setEditable(false);

            JTableBinding.ColumnBinding columnBinding1 = jTableBinding.addColumnBinding(ELProperty.create("${descripcion}"));

            columnBinding1.setColumnName("Detalle");
            columnBinding1.setColumnClass(String.class);
            columnBinding1.setEditable(false);

           
            bindingGroup.addBinding(jTableBinding);
            bindingGroup.bind();
            

        }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jtLista = new javax.swing.JTable();
        jlblTitulo = new javax.swing.JLabel();
        jbAceptar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jtLista.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Codigo", "Descripcion"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jtLista);

        jlblTitulo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jlblTitulo.setText("TITULO");

        jbAceptar.setText("ACEPTAR");
        jbAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbAceptarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 606, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jlblTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, 235, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(180, 180, 180))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jbAceptar)
                        .addGap(263, 263, 263))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jlblTitulo)
                .addGap(7, 7, 7)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbAceptar)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAceptarActionPerformed
         int filaElegida = this.jtLista.getSelectedRow();

     if (filaElegida < 0) {
          Utiles_MensajesDialogo.mensajeError("Debe elegir una fila!");
          this.jtLista.requestFocus();
          return;
      }

         SimpleEntidadTO elemento = this.lista.get(this.jtLista.convertRowIndexToModel(filaElegida));
         iframe.asignaEntidadEncontrada(elemento);
         this.dispose();
    }//GEN-LAST:event_jbAceptarActionPerformed

    /**
    * @param args the command line arguments
    */
  

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbAceptar;
    private javax.swing.JLabel jlblTitulo;
    private javax.swing.JTable jtLista;
    // End of variables declaration//GEN-END:variables

}
